﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Entity;
namespace DAO
{
    public class ManagedByDAO
    {
        BMS_DatabaseEntities context = new BMS_DatabaseEntities();

        public List<ManagedByEntity> LoadHistorySale(string company)
        {
            var query = from c in context.MANAGED_BY
                        where c.COMPANY_NAME == company
                        orderby c.MANAGED_CODE descending
                        select new ManagedByEntity
                        {
                            StaffName = c.STAFF_NAME,
                            Email = c.EMAIL,
                            Tel = c.TEL,
                            //Position = c.POSITION,
                            ManagedFrom = (DateTime)c.MANAGED_FROM,
                            ManagedTo = (DateTime)c.MANAGED_TO,
                        };
            return query.ToList<ManagedByEntity>();
        }

        public string GetPreviousSale(string company)
        {
            var query = (from c in context.MANAGED_BY where c.COMPANY_NAME == company select c).FirstOrDefault();

            return query.STAFF_NAME.ToString();
        }

        public void AddHistorySale(ManagedByEntity info)
        {
            var query = new MANAGED_BY
            {
                STAFF_NAME = info.StaffName,
                //COMPANY_NAME = info.CompanyName,
                //POSITION = info.Position,
                TEL = info.Tel,
                EMAIL = info.Email,
                MANAGED_FROM = (DateTime)info.ManagedFrom,
                MANAGED_TO = (DateTime)info.ManagedTo,
            };

            context.MANAGED_BY.Add(query);
            context.SaveChanges();
        }
    }
}
